package com.qf.job;

import com.qf.constant.CacheConstants;
import com.qf.constant.RabbitMQConstants;
import com.qf.mq.MqListener;
import com.qf.util.JavaMailUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;

/**
 * author:z
 * time:2022/1/3 20:58
 * description:定时器
 */
@Slf4j
@Component
//分布式任务调度系统 ElasticJob
public class MqJob implements SimpleJob {

    @Autowired
    JavaMailUtil javaMailUtil;

    @Autowired
    MqListener mqListener;

    @Override
    public void execute(ShardingContext shardingContext) {
        //监听队列 返回监听消息总数
        int mqMessagesCount = mqListener.getMqMessagesCount(RabbitMQConstants.TOPIC_SMS_SEND_LOG);
        //超过消息条数 发送邮件报警
        if(mqMessagesCount>=8){
            log.info("[监控模块-接收队列消息]，队列炸了，快来个人处理！");
            try {
//                javaMailUtil.sendMailForQueue(RabbitMQConstants.TOPIC_SMS_SEND_LOG,mqMessagesCount);
                log.info("[监控模块-接收队列消息]，发送邮件格式不对，请重新发送");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }
}
